package com.ruoyi.common.enums.fission;

import cn.hutool.core.util.ObjectUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor
public enum RewardTypeEnum {
    PRODUCT(1, "产品"),
    POINTS(2, "积分");

    private final Integer code;
    private final String desc;


    private static final Map<Integer, RewardTypeEnum> ENUM_MAP;

    static {
        RewardTypeEnum[] values = values();
        Map<Integer, RewardTypeEnum> enToCn = new HashMap<>(values.length);
        for (RewardTypeEnum value : values) {
            enToCn.put(value.getCode(), value);
        }
        ENUM_MAP = Collections.unmodifiableMap(enToCn);
    }

    /**
     * 根据类型查找枚举
     */
    public static RewardTypeEnum getEnumByType(Integer type) {
        RewardTypeEnum rewardTypeEnum = ENUM_MAP.get(type);
        if (ObjectUtil.isEmpty(rewardTypeEnum)) {
            throw new RuntimeException("类型有误");
        }
        return rewardTypeEnum;
    }

}
